package com.cmsz.uregs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cmsz.uregs.dao.AdminRepository;
import com.cmsz.uregs.entity.Admin;
import com.cmsz.uregs.service.AdminService;

@Service
public class AdminServiceImpl implements AdminService {
	
	@Autowired
	AdminRepository adminRepository;

	@Override
	@Transactional
	public Admin addAdmin(Admin admin) {
		return adminRepository.saveAndFlush(admin);
	}

	@Override
	@Transactional
	public void updateAdmin(Admin admin) {
		adminRepository.saveAndFlush(admin);
	}

	@Override
	@Transactional
	public void deleteAdmin(int id) {
		adminRepository.delete(id);
	}

	@Override
	public List<Admin> findAllAdmins() {
		return adminRepository.findAll();
	}

	@Override
	public Admin findAdmin(int id) {
		return adminRepository.findOne(id);
	}

	@Override
	public Admin findAdminByName(String username) {
		return adminRepository.findByUsername(username);
	}

}
